function close_modal(target) {
    $(".md-overlay").fadeOut(200);
    $(target).css({
        "display": "none"
    });
}

function open_modal(modal_id) {
    modal_id = "#" + modal_id;
    var overlay = $("<div class='md-overlay'></div>");
    $("body").append(overlay);
    $(".md-overlay").css({
        "display": "block",
        opacity: 0
    });
    $(".md-overlay").fadeTo(200, 0.45);
    var modal_width = $(modal_id).outerWidth();
    $(modal_id).css({
        "display": "block",
        "position": "fixed",
        "opacity": 0,
        "z-index": 11000,
        "left": 50 + "%",
        "margin-left": -(modal_width / 2) + "px",
        "top": 200 + "px"
    });
    $(modal_id).fadeTo(200, 1);

    $(".md-overlay").bind('click', function (e) {
        close_modal(".md-modal");
        e.preventDefault();
    });
    $(".md-close").bind('click', function (e) {
        close_modal(".md-modal");
        e.preventDefault();
    });

    //e.preventDefault();
}

